/**
 * Copyright (c) 2024-2025 National Fundamental Software of China Co., Ltd.
 *
 * You should have find a copy of NFSChina License. If not, please contact us
 * by email <os_support@nfschina>
 *
**/

import QtQuick 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.plasmoid 2.0

Item {
	id: appletIcon
	property string source: ''
	property bool active: false
	readonly property bool usingPackageSvg: filename
	readonly property string filename: source ? plasmoid.file('', 'icons/' + source + '.svg') : ''
	readonly property int minSize: Math.min(width, height)
	property bool smooth: true
	readonly property real scaleFactor: PlasmaCore.Units.devicePixelRatio

	PlasmaCore.IconItem {
		anchors.centerIn: parent
		visible: appletIcon.usingPackageSvg
		source: appletIcon.source
		active: false
		smooth: appletIcon.smooth
		width: 24 * scaleFactor
		height: 24 * scaleFactor
		roundToIconSize: false
		usesPlasmaTheme: true
	}

	PlasmaCore.SvgItem {
		id: svgItem
		anchors.centerIn: parent
		readonly property real minSize: Math.min(naturalSize.width, naturalSize.height)
		readonly property real widthRatio: naturalSize.width / svgItem.minSize
		readonly property real heightRatio: naturalSize.height / svgItem.minSize
		width: appletIcon.minSize * widthRatio
		height: appletIcon.minSize * heightRatio

		smooth: appletIcon.smooth

		visible: !appletIcon.usingPackageSvg
		svg: PlasmaCore.Svg {
			id: svg
			imagePath: appletIcon.filename
		}
	}
	PlasmaCore.ToolTipArea {
        id: tooltip
        anchors.fill: parent
        mainText: i18n("Overview")
    }
}
